<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>

    <div id="app">
        <!-- <my-header></my-header> -->
        <Head-Son :fname="name" :msgreceive="receive"></Head-Son>
        <h1>子组件传递参数{{rmsg}}</h1>
    </div>

    <template id="header">
        <div>
            <button @click="getSds">点击</button>
        </div>
    </template>
    <template id="headSon">
        <div>
            <h2>父组件传递的参数{{fname}}</h2>
            <button @click="getDas">发送数据给父组件</button>
        </div>
    </template>

    <script>
        let HeadSon = {
            name: "HeadSon",
            template: "#headSon",
            data() {
                return {
                    text: "局部组件"
                }
            },
            methods: {
                getDas() {
                    console.log(this.msgreceive);
                    this.msgreceive(this.text);
                }

            },
            props: {
                fname: String,
                msgreceive: Function,
            }
        }
        Vue.component("my-header", {
            name: "my-header",
            template: "#header",
            data() {
                return {
                    txt: "全局组件",

                }
            },
            methods: {


            }
        })
        const app = new Vue({
            el: "#app",
            data: {
                name: "张三",
                rmsg: "",
            },
            methods: {
                receive(smsg) {
                    console.log(smsg);
                    // 函数的目的 就是接受 子组件传递进来的参数 然后赋值给  父组件事先创建好的 数据项
                    this.rmsg = smsg;

                }
            },
            components: {
                HeadSon,
            },
        });
    </script>
</body>

</html>